package td.slice;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import td.TD;

import distribution.Combination;

public class SixSliceComb {

	private List<Integer> codes;
	private int count = 0;

	public SixSliceComb(List<Integer> codes) {
		super();
		this.codes = codes;
		if (this.codes != null) {
			Collections.sort(this.codes);
		}
	}

	public SixSliceComb() {
		super();
		codes = new ArrayList<Integer>();
	}

	public void addCode(Integer code) {
		if (codes == null) {
			codes = new ArrayList<Integer>();
		}
		if (!codes.contains(code)) {
			codes.add(code);
			Collections.sort(this.codes);
		}
	}

	public void removeCode(Integer code) {
		if (codes != null) {
			if (!codes.contains(code)) {
				codes.remove(code);
				Collections.sort(this.codes);
			}
		}
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public List<List<Integer>> toCodes() {
		if (this.codes != null) {
			Combination<Integer> cc = new Combination<Integer>(this.codes);
			return cc.allCombination(3);
		}
		return null;
	}
	
	public List<TD> tdList() {
		List<TD> tdl = new ArrayList<TD>();
		if (this.codes != null) {
			Combination<Integer> cc = new Combination<Integer>(this.codes);
			List<List<Integer>> ll = cc.allCombination(3);
			for(List<Integer> l : ll){
				TD td = new TD(l);
				tdl.add(td);
			}
		}
		return tdl;
	}
}
